<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>

<%@ page import="com.onlineMIS.ORM.entity.headQ.user.*,java.util.Date,java.text.SimpleDateFormat"%>
<%@ page import="com.onlineMIS.ORM.entity.headQ.inventory.*"%>
<%@ page import="com.onlineMIS.common.Common_util"%>

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查询仓库单据</title>
<%@ include file="../../common/Style.jsp"%>

<script>
var selectCustName = 0;
var selectCustTag = 1;

function exportInventoryOrder(orderId){
	
		$("#orderId").val(orderId);
		$("#order_ID").val(orderId);
	    var url = "<%=request.getContextPath()%>/action/exportInventoryOrToExcel!ExportJinSuanOrder";
	    document.inventorySearchForm.action = url;
	    document.inventorySearchForm.submit();		
}

function previewInventoryOrder(orderId){
	window.open('inventoryOrder!previewOrder?formBean.order.order_ID='+orderId,'预览批发单据','height=800, width=1400, toolbar=no,scrollbars=yes, resizable=yes,  menubar=no, location=no, status=no');
}
$(document).ready(function(){
	$("#brandNums").val(0);
	$("#orderID").val("");
	$('#dlg').dialog('close')
	let status = $("#status").val();
	if(status !=0){
		$("#order_Status").tagbox('setValue',status);
	}
	$("#storeId").combobox('setValue',<%=Common_util.ALL_RECORD%>);
	parent.$.messager.progress('close'); 
	initDialog();//初始化筛选条件

	var params = $.serializeObject($('#inventorySearchForm'));
	
	$('#dataGrid').datagrid({
		url : 'inventoryOrderJSON!search',
		queryParams: params,
		fit : true,
		border : false,
		sortName : 'startTime',
		sortOrder : 'desc',
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		rownumbers:true,
		nowrap : false,
		checkbox:true,
		rowStyler: function(index,row){
			var style = "";
			if (row.status == <%=InventoryOrder.STATUS_DRAFT%>)
				style += 'color:blue;';
			else if (row.status == <%=InventoryOrder.STATUS_CANCELLED%>)
				style += 'color:red;';				
			return style;
		},
		columns : [ [ 
			{			
				field : 'checkOrder',
				title : '选择',
				width : 60,
				checkbox:true,
				align: 'center'
			},{
			field : 'id',
			title : '编号',
			width : 50
		}, {
			field : 'clientName',
			title : '客户名称',
			width : 120,
			sortable:true,
			order:'desc'
				
		}, {
			field : 'startTime',
			title : '开始时间',
			width : 95,
			sortable:true,
			order:'desc'
		}, {
			field : 'completeTime',
			title : '过账时间',
			width : 95,
			sortable:true,
			order:'desc'
		}, {
			field : 'PDAUserName',
			title : 'PDA录入',
			width : 68,
			sortable:true,
			order:'desc'
		},  {
			field : 'storeName',
			title : '发货库房',
			width : 70,
			sortable:true,
			order:'desc'
		},{
			field : 'keeperName',
			title : '仓库录入',
			width : 68,
			sortable:true,
			order:'desc'
		}, {
			field : 'auditorName',
			title : '审核人员',
			width : 68,
			sortable:true,
			order:'desc'
		}, {
			field : 'importTimes',
			title : '导精算',
			width : 55,
			sortable:true,
			order:'desc'
		}, {
			field : 'totalQ',
			title : '总数',
			width : 60
		}, {
			field : 'totalWholeSales',
			title : '批发总额',
			width : 80,
			formatter: function (value, row, index){
				return (row.totalWholeSales).toFixed(2);
			}
		}, {
			field : 'comment',
			title : '备注',
			width : 130
		}, {
			field : 'daimai',
			title : '代卖',
			width : 40,
			sortable:true,
			order:'desc'
		}, {			
			field : 'maiduan',
			title : '买断',
			width : 40,
			sortable:true,
			order:'desc'
		}, {
	
			field : 'transfer',
			title : '调货',
			width : 40,
			sortable:true,
			order:'desc'
		}, {			
			field : 'process',
			title : '单据进程',
			width : 70,
			sortable:true,
			order:'desc'
		}, {
			field : 'orderType',
			title : '单据类型',
			width : 75,
			sortable:true,
			order:'desc',
			formatter :  function(value, row, index) {

				if(row.id == 0){
					var str = "";
				}else if(row.orderTypeI == <%=InventoryOrder.TYPE_SALES_ORDER_W%>){
					var str = $.formatString('<button class="button">销售单</button>');
				}else if(row.orderTypeI == <%=InventoryOrder.TYPE_SALES_RETURN_ORDER_W%>){
					var str = $.formatString('<button class="button1">退货单</button>');
				}else if(row.orderTypeI == <%=InventoryOrder.TYPE_SALES_FREE_ORDER_W%>){
					var str = $.formatString('<button class="button2">赠送单</button>');
				}
				
				return str;
			}
		}, {					
			field : 'action',
			title : '查看/修改',
			align: 'center',
			width : 70,
			formatter : function(value, row, index) {
				var str = '';
				if (row.isAuthorizedToEdit == true){
					var url = "<%=request.getContextPath()%>/action/inventoryOrder!loadOrder?formBean.order.order_ID=" + row.id;
					str += $.formatString('<a href="#" onclick="addTab6(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="修改"/></a>', url, '单据 ' + row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');
				}
				
				return str;
			}
		}, {					
			field : 'action2',
			title : '权限转移',
			width : 120,
			formatter : function(value, row, index) {
				var str = '';
				if (row.isAuthorizedToTransfer == true){
					var dropDown = "<select id='transferTo"+row.id+"'>";
					<s:iterator value="uiBean.users" status = "st" id="user" >
					   dropDown +="<option value='<s:property value="#user.user_id"/>'><s:property value="#user.user_name"/></option>";
					</s:iterator>
					dropDown +="</select>";
					
					str += $.formatString(dropDown + ' <input type="button" value="转移单据" onclick="transferOrderToOther(\'{0}\',\'{1}\');"/>', row.id);
				}
				
				return str;}
		}, {					
			field : 'action3',
			title : '单据下载',
			align: 'center',
			width : 70,
			formatter : function(value, row, index) {
				var str = '';				
				if(row.id != 0){
					str += $.formatString('<a href="#" onclick="exportInventoryOrder(\'{0}\');"><img border="0" src="{1}" title="单据下载"/></a>', row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/download3.png');								
				}
				return str;
			}
		}, {					
			field : 'action4',
			title : '单据预览',
			align: 'center',
			width : 70,
			formatter : function(value, row, index) {
				var str = '';				
				if(row.id != 0){
					str += $.formatString('<a href="#" onclick="previewInventoryOrder(\'{0}\');"><img border="0" src="{1}" title="单据预览"/></a>', row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/preview2.png');								
				}
				return str;
			}
		}
		]],
		toolbar : '#toolbar'
	});
});
function transferOrderToOther(orderId){
	var transferToUserId = $("#transferTo"+orderId).val();
	var params = "formBean.order.order_ID=" + orderId + "&formBean.user.user_id="+ transferToUserId;
	var url = "<%=request.getContextPath()%>/action/inventoryOrderJSON!transferOrderToOther";

	$.post(url,params, transferBk,"json");
	
}
function transferBk(data){
	var returnCode = data.returnCode;
	if (returnCode == SUCCESS){
		$.messager.alert('操作成功', "成功转移单据,即刻刷新单据", 'info');
		searchOrder();
	} else {
		$.messager.alert('操作失败', data.message, 'error');
	}
}
/**
 * 单据搜索
 */
function searchOrder(){

	initDialog();
	var params = $.serializeObject($('#inventorySearchForm')); 
	$('#dataGrid').datagrid('load',params); 	
}

/**
 * 初始化筛选条件
 */
function initDialog(){
	var tagGroup = $('#tagsD').tagbox('getValues');
	var orderId2 = $("#orderID2").textbox('getValue');
	var dComment = $("#commentD").textbox('getValue');
	var pbs = $("#pbs").val();
	var storeId = $("#storeId").val();
	
	 $("#tagGroups").val(tagGroup.toString());
	 $("#orderId").val(orderId2);
	 $("#productCodes").val(pbs);
	 $("#comment").val(dComment);
	 $("#headqStoreId").val(storeId);
	 var id = $("#headqStoreId").val();
}

/**
 * 单据下载
 */
function downloadSaleInfo(){
	document.inventorySearchForm.action="inventoryOrder!downloadSaleInfo";
	document.inventorySearchForm.submit();
}

function searchOrderById(){
	var orderId = $("#orderID2").textbox('getValue');	
	if(orderId == "" || orderId == null){
		$.messager.alert('提示', '请输入单据号,单据号不能为空', 'warning');
	}else{
		let isNum = is_number(orderId);
		if(isNum){
			searchOrder();
		}else{
			$.messager.alert('提示', '非法输入，请输入正确的单据号', 'warning');
		}		
	}	
}
//重置
function reset(){
	delectCust();
	$("#order_type").combobox('setValue',-1);
	$("#order_Status").combobox('setValue',-1);
	$("#accountant").combobox('setValue',-1);
	
	
	$("#order_Status").tagbox('clear');
	 $("#tagsD").tagbox('clear');
	 $("#orderID2").textbox('setValue','');
	 $("#commentD").textbox('setValue','');
	 $("#pbs").val();
	 deletepbs();
	
	 $("#tags").val();
	 $("#orderId").val(0);
	 $("#productCodes").val();
	 $("#comment").val();
	 searchOrder();
	 
}


/**
 * 下载校验
 */
function validateCheckbox(){
		
	var rows = $('#dataGrid').datagrid('getChecked');
	var barcodes = [];
	if (rows.length == 0){
		 $.messager.alert('下载提示','请先选中货品!','warning');
		return false;
	}
	return true;
}
/**
 * 合并下载
 */
function mergeDownload(){
	var rows = $('#dataGrid').datagrid('getChecked');
	var orderIds = [];
	
	if (validateCheckbox()){
		for(var i=0;i<rows.length;i++){
			orderIds.push(rows[i].id);
		}	
		$("#orderIds").val(orderIds);
	    var url = "<%=request.getContextPath()%>/action/exportInventoryOrToExcel!ExportJinSuanOrders";
	    document.inventorySearchForm.action = url;
		document.inventorySearchForm.submit();	
		$("#orderIds").val("");
	}
}

</script>

</head>
<body>
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',border:false" style="height: 90px;">
			<s:form id="inventorySearchForm" name="inventorySearchForm" action="" theme="simple" method="POST">
				<s:hidden name="formBean.order.orderId" id="orderId"/>
				<s:hidden name="formBean.order.order_ID" id="order_ID"/>
				<s:hidden name="formBean.orderIds" id="orderIds"/>
				<s:hidden name="formBean.pbIds" id="productCodes"/>
				<s:hidden name="formBean.tagGroups" id="tagGroups"/>
				<s:hidden name="formBean.order.comment" id="comment"/>
				<s:hidden name="formBean.order.store.id" id="headqStoreId"/>
				<s:hidden name="formBean.order.order_Status" id="status"/>

				<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="50" colspan="7">
										<table width="100%" border="0">
											<tr class="PBAOuterTableTitale">
												<td height="24" colspan="11">销售单据：
												</td>
											</tr>
											<tr class="InnerTableContent">
												<td width="5%" height="19" align="center"><strong>单据时间：</strong></td>
												<td width="20%"><s:textfield id="startDate"
														name="formBean.search_Start_Time"
														cssClass="easyui-datebox"
														data-options="width:100,editable:false" /> &nbsp;至 &nbsp;
													<s:textfield id="endDate" name="formBean.search_End_Time"
														cssClass="easyui-datebox"
														data-options="width:100,editable:false" /></td>
												
												<td width="16%"><%@ include file="../common/HeadqCustInput.jsp"%> </td>
												<td width="5%"  align="center"><strong>单据种类：</strong></td>
												<td width="8%" ><s:select name="formBean.order.order_type"
														cssClass="easyui-combobox" style="width:130px;text-align: center"
														id="order_type" list="uiBean.orderTypeMap" listKey="key"
														data-options="prompt:'请选择单据种类',editable:false"
														listValue="value" headerKey="-1" headerValue="" /></td>
												<td width="4%"  align="center"><strong>状态：</strong></td>
												<td width="20%">
														<input class="easyui-tagbox" id="order_Status" name="formBean.order.orderStatus" style="width:300px" data-options="
											                url: 'inventoryOrderJSON!listOrderStatusTags',
											                method: 'get',											                
											                valueField: 'id',
											                textField: 'text',
											                limitToList: true,
											                hasDownArrow: true,
											                prompt: '请选择状态',
											                tagStyler: function(value){										                    
										                      return 'background:#ffd7d7;color:#c65353';										                   
										                }
											                ">														
														</td>
												<td width="4%"  align="center"><strong>会计：</strong></td>
												<td width="5%"><s:select
														name="formBean.order.order_Auditor.user_id"
														cssClass="easyui-combobox" style="width:130px;text-align: center"
														id="accountant" list="uiBean.users" listKey="user_id"
														data-options="prompt:'请选择会计',editable:false"
														listValue="user_name" headerKey="-1"
														headerValue="" /></td>
												<td></td>
												<td>
													<a class="easyui-linkbutton c3"  data-options="iconCls:'icon-filter',plain:true" onclick="reset()">重置</a>
													<a class="easyui-linkbutton c6"  data-options="iconCls:'icon-filter',plain:true" onclick="$('#dlg').dialog('open')">更多筛选</a> 
												</td>		
						
											</tr>											
										
																						
										</table>
									</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		
		<div id="dlg" class="easyui-dialog" title="条件筛选" style="right:200px;width:600px;height:300px;padding:10px"
											            data-options="
											                iconCls: 'icon-tip',             
											                buttons: [{
											                    text:'确认选择',
											                    iconCls:'icon-ok',
											                    handler:function(){
											                       searchOrder();
											                       $('#dlg').dialog('close');
											                    }
											                }]
											            ">
											        <table width="100%" border="0">
											        	<tr>
											        		<td width="10%" align="center"><strong>客户标签：</strong></td>
																<td  width="20%" colspan="3"><input class="easyui-tagbox"  id="tagsD"  style="width:360px;" data-options="
															                url: 'headQCustMgmtJSONAction!listCusTags',
															                method: 'get',
															                groupField:'groupName',
															                value: '',
															                valueField: 'id',
															                textField: 'tagName',
															                limitToList: true,
															                hasDownArrow: true,
															                prompt: '选择客户标签',
															                tagStyler: function(value){
														                    if (value >0 && value <=3){
														                        return 'background:#ffd7d7;color:#c65353';
														                    } else if (value >= 4 && value <17){
														                        return 'background:#76EEC6;color:#c65353';
														                    }else if (value >= 17 && value <19){
														                        return 'background:#7EC0EE;color:#c65353';
														                    }else if (value >= 19 ){
														                        return 'background:#EEB422;color:#c65353';
														                    }
														                }
															                "></td>
											        	</tr>
											        	<tr>
											        		<td align="center"><strong>包含货品：</strong></td> 
 															<td><%@ include file="../common/ProductCodeInput.jsp"%> </td>
											        	</tr>
											        	<tr>
											        		<td  width="4%" align="center"><strong>单据号：</strong></td>
															<td width="5%">
															<s:textfield cssClass="easyui-searchbox" id="orderID2" data-options="prompt:'请输入单据号',searcher:searchOrderById"  size="20" />
															</td>
											        	</tr>
											        	<tr>
											        		<td width="3%" align="center"><strong>单据备注：</strong></td>
															<td width="12%"><input id="commentD"
																class="easyui-textbox" data-options="prompt:'请输入单据备注'"
																 size="20" /></td>
											        	</tr>
											        	<tr>
											        		<td width="3%" align="center"><strong>库房：</strong></td>
															<td width="12%"><s:select name="formBean.order.store.id" id="storeId"  list="uiBean.stores" listKey="id" listValue="name" style="width:140px" cssClass="easyui-combobox"   data-options="editable:false" /></td>
											        	</tr>
											        	
											        	
											        </table>
											    </div>
			</s:form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid" border="0">
			</table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
		
				<a class="easyui-linkbutton" style="height:27px;"  data-options="iconCls:'icon-search',plain:true" onclick="searchOrder();">查询单据</a>
				<a class="easyui-linkbutton" style="height:27px;" data-options="iconCls:'icon-print',plain:true" onclick="downloadSaleInfo();">下载汇总</a>
				<a class="easyui-linkbutton" style="height:27px;" data-options="iconCls:'icon-print',plain:true" onclick="mergeDownload();">合并下载</a>  
								
	</div>

</body>
</html>